package com.exam.api.common;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author bcheng
 * @Create 2023/9/9 16:05
 * @Description Runnable 包装类
 */
@Slf4j
@AllArgsConstructor
public class RunnableWrapper implements Runnable {

    private final Runnable runnable;

    private final Runnable beforeCallback;

    private final Runnable afterCallback;

    @Override
    public void run() {
        try {
            try {
                beforeCallback.run();
            } catch (Exception e) {
                log.error(" <<<=== RunnableWrapper装饰器错误 ", e);
            }
            runnable.run();
        } finally {
            afterCallback.run();
        }
    }
}
